
<?php

function dal_achievement_get($userid, $gameid)
{
	$t_conn   = dal_mocool_get_dbconn();
	$t_sql    = "select achi_id from mocool_achievement_table where user_id=$userid and game_id=$gameid";
	$t_result = mysql_query($t_sql, $t_conn);
	if (!$t_result) {
		dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
		return null;
	}
	
	$t_ret = Array();
	while ($row = mysql_fetch_array($t_result)) {
		array_push($t_ret, $row['achi_id']);
	}
	
	return $t_ret;
}

function dal_achievement_update($userid, $gameid, $list)
{
	$t_list = dal_achievement_get($userid, $gameid);
	$t_conn = dal_mocool_get_dbconn();
	
	foreach ($list as $key => $value) {
		$t_exist = false;
		foreach ($t_list as $key => $value) {
			if ($value == $value) {
				$t_exist = true;
				break;
			}
		}
		
		if (!$t_exist) {
			$t_sql    = "insert into mocool_achievement_table values($userid, $gameid, $value, NOW())";
			$t_result = mysql_query($t_sql, $t_conn);
			if (!$t_result) {
				dal_mysql_error($t_conn, $t_sql, __FUNCTION__);
				return false;
			}
		}
	}
	
	return true;
}

?>
